<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <style>

        .inputremindPeple {
            max-width: 200px;
            height: 26px;
            display: inline-block;
        }
    </style>

</head>

<body class="white-bg" style="color:#333;padding:3px;">
<div class="white-bg setRemindPeopleK" style="margin:10px">
    <form action="" class="form-group" id="add">

        <table class="table table-bordered white-bg">

            <tr>
                <td class="text-right"><label for="devideNum">分组编号</label><span class="colorRed">*</span></td>
                <td colspan="3"><input type="text" class="form-control inputremindPeple" id="devideNum"
                                       name="sn" value="{:isset($data)?$data.sn:''}">(最多输入四位数字，不允许重复)
                </td>
            </tr>
            <tr>
                <td class="text-right"><label for="devideName">分组名称</label><span class="colorRed">*</span></td>
                <td colspan="3"><input type="text" class="form-control inputremindPeple" id="devideName"
                                       name="title" value="{:isset($data)?$data.title:''}">(不允许重复)
                </td>
            </tr>
            <tr>
                <td class="text-center"><label for="brief"></label></td>
                <td colspan="3"><textarea style="width: 60%;height: 100%;padding: 20px;user-select:none"
                                          id="brief" name="brief">{:isset($data)?$data.brief:''}</textarea>(200)
                </td>
            </tr>
            <tr>
                <td colspan="4" class="text-center">
                    <button class="btn btn-success" type="submit" id="tijiao">保存</button>
                    <button class="btn btn-warning " id="cancelBack">返回</button>
                </td>
            </tr>

        </table>
    </form>
</div>

<!-- 全局js -->
{include file="Public/footer"}
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script>
    var cancelBack = document.getElementById('cancelBack')
    cancelBack.onclick = function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    /**
     * touxingren (首次从 URL 获取数据，显示 header，不显示按钮，忽略大小写，可清除)
     */
    $("#testNoBtn").bsSuggest({
        url: "{:url('jxsgl/provicejson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias: {userName: "姓名"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onDataRequestSuccess', function (e, result) {
        console.log('onDataRequestSuccess: ', result);
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#renyuan .ren').each(function (idx, o) {
            if ($(this).data('id') == keyword.id) {
                bool = true;
            }
        })
        if (bool == false)
            $('#renyuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<span class="close">×</span></span>')
        //console.log('onSetSelectValue: ', keyword, data);
    }).on('onUnsetSelectValue', function () {
        console.log("onUnsetSelectValue");
    });

    //弹窗选择提醒人
    $('#select').on('click', function () {
        var index = layer.getFrameIndex(window.name)
        //iframe层-父子操作
        layer.open({
            type: 2,
            title: '请选择提醒人员',
            area: ['500px', '400px'],
            fixed: false, //不固定
            maxmin: true,
            content: '{:url("jxsgl/selectsalesman")}?frameindex=' + index
        });
        return false
    })

    //提交
    $('#tijiao').on('click',function () {
        var form =  $('#add')
        var serial = form.serialize()

        $.ajax({
            'type':'post',
            'url':form.attr('action'),
            'data':serial,
            'dataType':'json',
            'success':function (data) {
                if(data.success){
                    swal({
                        title: data.msg,
                        type: "success"
                    },function(){
                        parent.history.go(0)
                    });

                }else
                    swal({
                        title: data.msg,
                        type: "warning"
                    });
            }
        })
        return false
    })

</script>
</body>

</html>